package com.my.biao.activity;

import android.support.v4.app.Fragment;
import android.widget.RadioGroup;

import com.my.biao.R;
import com.my.biao.adapter.ViewPagerAdapter;
import com.my.biao.base.BaseActivity;
import com.my.biao.constant.NetWorkConstant;
import com.my.biao.fragment.AddBillFragment;
import com.my.biao.fragment.BillFragment;
import com.my.biao.fragment.UserFragment;
import com.my.biao.util.SharedPrefUtil;
import com.my.biao.view.MainViewPager;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener {
    private SharedPrefUtil sp;
    private MainViewPager viewPager;
    private ViewPagerAdapter adapter;
    private List<Fragment> fragments = new ArrayList<Fragment>();
    private RadioGroup radioGroup;

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_main);
    }


    @Override
    public int netWorkChangeState(int i) {
        return super.netWorkChangeState(i);
    }


    @Override
    public void initView() {
        viewPager = findViewById(R.id.mian_viewPager);
        radioGroup = findViewById(R.id.rg_main);

        fragments.add(new BillFragment());
        fragments.add(new AddBillFragment());
        fragments.add(new UserFragment());

        adapter = new ViewPagerAdapter(getSupportFragmentManager(), fragments);
    }

    @Override
    public void initListener() {
        viewPager.setAdapter(adapter);
        viewPager.setCurrentItem(NetWorkConstant.BIAO_BILL_FRAGMENT);
        radioGroup.setOnCheckedChangeListener(this);
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.rb_bill: // 账单
                viewPager.setCurrentItem(NetWorkConstant.BIAO_BILL_FRAGMENT);
                break;
            case R.id.rb_add_bill: // 记账
                viewPager.setCurrentItem(NetWorkConstant.BIAO_ADD_BILL_FRAGMENT);
                break;
            case R.id.rb_user: // 账户
                viewPager.setCurrentItem(NetWorkConstant.BIAO_USER_FRAGMENT);
                break;
            default:
                break;
        }
    }
}
